package cn.net.yugu.doraemon.dubbo.trace;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;

import java.util.UUID;

/**
 * @description:
 * @author: wanghongli
 * @create: 2022-07-12 13:51:20
 */
@Slf4j
public final class TraceIdUtils {
    public static String getTraceId() {
        return MDC.get(TraceConstant.TRACE_ID);
    }

    public static String generateTraceId() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    public static void set(String traceId) {
        MDC.put(TraceConstant.TRACE_ID, traceId);
    }

    public static void clear() {
        MDC.remove(TraceConstant.TRACE_ID);
    }
}
